package com.hhs.storage.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.hhs.storage.bean.InputParam;
import com.hhs.storage.bean.Result;
import com.hhs.storage.bean.YymFl;
import com.hhs.storage.service.YymFlService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yuanjun
 * @since 2020-08-19
 */
@RestController
@RequestMapping("/app/yymfl")
@Slf4j
public class AppYymFlController {
    @Resource
    YymFlService  yymFlService;
    @RequestMapping(value = "getAll")
    public Map<String, Object> getAll(InputParam inputParam) {
        log.info("查询分类全部信息");
        EntityWrapper ew = new EntityWrapper<YymFl>();
        ew.orderBy("type_",false);
        List<YymFl> result = yymFlService.selectList(ew);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("rows",result);
        map.put("total",result.size());
        return map;
    }
    @RequestMapping(value = "getAllOne")
    public Map<String, Object> getAllOne(InputParam inputParam) {
        log.info("查询分类全部信息");
        EntityWrapper ew = new EntityWrapper<YymFl>();
        ew.orderBy("type_",false);
        ew.eq("type_",0);
        List<YymFl> result = yymFlService.selectList(ew);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("rows",result);
        map.put("total",result.size());
        return map;
    }

    @RequestMapping(value = "getAllTwo")
    public Map<String, Object> getAllTwo(InputParam inputParam) {
        log.info("查询附近全部信息");
        EntityWrapper ew = new EntityWrapper<YymFl>();
        ew.orderBy("type_",false);
        ew.eq("type_",1);
        List<YymFl> result = yymFlService.selectList(ew);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("rows",result);
        map.put("total",result.size());
        return map;
    }

    @RequestMapping(value = "getAllThree")
    public Map<String, Object> getAllThree(InputParam inputParam) {
        log.info("查询头号码全部信息");
        EntityWrapper ew = new EntityWrapper<YymFl>();
        ew.orderBy("type_",false);
        ew.eq("type_",2);
        List<YymFl> result = yymFlService.selectList(ew);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("rows",result);
        map.put("total",result.size());
        return map;
    }

    @RequestMapping(value = "getAllFour")
    public Map<String, Object> getAllFour(InputParam inputParam) {
        log.info("查询号码段全部信息");
        EntityWrapper ew = new EntityWrapper<YymFl>();
        ew.orderBy("type_",false);
        ew.eq("type_",3);
        List<YymFl> result = yymFlService.selectList(ew);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("rows",result);
        map.put("total",result.size());
        return map;
    }

    @RequestMapping(value = "getAllFive")
    public Map<String, Object> getAllFive(InputParam inputParam) {
        log.info("查询生成数量全部信息");
        EntityWrapper ew = new EntityWrapper<YymFl>();
        ew.orderBy("type_",false);
        ew.eq("type_",4);
        List<YymFl> result = yymFlService.selectList(ew);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("rows",result);
        map.put("total",result.size());
        return map;
    }
    @RequestMapping(value = "getAllSix")
    public Map<String, Object> getAllSix(InputParam inputParam) {
        log.info("查询采集管理全部信息");
        EntityWrapper ew = new EntityWrapper<YymFl>();
        ew.orderBy("type_",false);
        ew.eq("type_",5);
        List<YymFl> result = yymFlService.selectList(ew);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("rows",result);
        map.put("total",result.size());
        return map;
    }
    @RequestMapping(value = "delete/{id}", method = RequestMethod.DELETE)
    public Map<String, Object> dele(@PathVariable("id") String id) {
        log.info("删除人员");
        yymFlService.delete(new EntityWrapper<YymFl>().eq("id_", id));
        return Result.sucJsonResp(null);
    }

    @RequestMapping(value = "save")
    public Map<String, Object> saveOrUpdate(YymFl fl){
        log.info("新增分类信息");
        boolean ins = yymFlService.insert(fl);
        if(ins==true){
            return Result.sucJsonResp(null);
        }
        return Result.failJsonResp("未知错误");
    }
}

